package basic.Test;

enum Signal {
	GREEN, YELLOW, RED
}

// 所有枚举类都继承了Enum的方法,枚举类是class有构造器，方法和数据域
enum Color2 {
	RED(255, 0, 0), BLUE(0, 0, 255), BLACK(0, 0, 0), YELLOW(255, 255, 0), GREEN(
			0, 255, 0);
	private Color2(int rv, int gv, int bv) {
		this.redValue = rv;
		this.greenValue = gv;
		this.blueValue = bv;
	}

	public String toString() { // 覆盖了父类Enum的toString()
		return super.toString() + "(" + redValue + "," + greenValue + ","
				+ blueValue + ")";
	}

	private int redValue; // 自定义数据域,private为了封装。
	private int greenValue;
	private int blueValue;
}

public class EnumTest {

	public static void main(String[] args) {
		// Color2 colors=new Color2（100，200，300）; //wrong
		Color2 color = Color2.RED;
		System.out.println(color);

		System.out.println("----------------------------");
		// values()方法： 静态方法，返回一个包含全部枚举值的数组
		for (Color2 c : Color2.values()) {
			// 返回枚举值在枚举类种的顺序
			System.out.println("ordinal: " + c.ordinal());
			// toString方法： 返回枚举常量的名称
			System.out.println(c);
			System.out.println(c.name());
		}
		System.out.println("----------------------------");

		// compareTo返回的是两个枚举值的顺序之差
		System.out.println("Color2.RED.compareTo(Color2.BLUE): "
				+ Color2.RED.compareTo(Color2.BLUE));

		testswitch();
	}

	public static void testswitch() {
		Signal color = Signal.RED;
		switch (color) {
		case RED:
			System.out.println(Signal.RED);
			break;
		case YELLOW:
			System.out.println(Signal.YELLOW);
			break;
		case GREEN:
			System.out.println(Signal.GREEN);
			break;
		}

	}
}
